<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <#include "../common/header.ftl">
</head>
<body>

<div class="container" style="margin-top: 20px">
    <#include "../common/top.ftl">
    <div class="row">
        <div class="col-sm-3">
            <#include "../common/menu.ftl">
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">积分商品管理</h1>
                </div>
            </div>
            <#--高级查询--->
            <form class="form-inline" id="searchForm" action="/signStore/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <div class="form-group">
                    <label>关键字:</label>
                    <input type="text" class="form-control" name="keyword" value="${(qo.keyword)!}"
                           placeholder="请输商品标题">
                </div>
                <button id="btn_query" class="btn btn-default">
                    <span class="glyphicon glyphicon-search"></span> 查询
                </button>
                <a href="javascript:" class="btn btn-success inputBtn">
                    <span class="glyphicon glyphicon-plus"></span> 添加商品
                </a>
            </form>

            <table class="table table-striped table-hover" >
                <tr>
                    <th>编号</th>
                    <th>商品标题</th>
                    <th>商品价格</th>
                    <th>所需积分</th>
                    <th>商品图片</th>
                    <th></th>
                </tr>
                <#--使用Freemark的指令完成循环迭代-->
                <#list pageInfo.list as entity>
                    <tr>
                        <td>${entity_index + 1}</td>
                        <td>${entity.productTitle!}</td>
                        <td>${entity.productPrice!}</td>
                        <td>${entity.productSign!}</td>
                        <td><img src="${entity.productUrl}" width="30px" /></td>
                        <td>
                            
                            <a href="javascript:" class="btn btn-success btn-xs inputBtn" data-json='${entity.json}'>
                                <span class="glyphicon glyphicon-pencil"></span> 修改
                            </a>
                            <a href="javascript:" class="btn btn-danger  btn-xs deleteBtn" data-tid="${entity.id}">
                                <span class="glyphicon glyphicon-remove"></span> 删除
                            </a>
                        </td>
                    </tr>
                </#list>
            </table>

            <#include "../common/page.ftl">
        </div>
    </div>
</div>

<#--模态框必须是body的子元素-->
<div class="modal fade" id="signStoreModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog ">
        <div class="modal-content">
        <#--模态框标题-->
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">新增/编辑</h4>
            </div>
        <#--模态框正文-->
            <div class="modal-body1">
            <#--填充编辑界面-->
                <form class="form-horizontal" action="/signStore/saveOrUpdate.do" method="post" id="signStoreForm"
                      enctype="multipart/form-data">
                    <input type="hidden" name="id"/>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">商品标题：</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" name="productTitle" placeholder="请输商品标题"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">商品价格：</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" name="productPrice" placeholder="请输入商品价格"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">所需积分：</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" name="productSign" placeholder="请输入所需积分"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">商品图片：</label>
                        <div class="col-lg-6">
                            <img id="photoUrl" width="100%"> <!--用来显示-->
                            <input type="hidden" class="form-control" name="productUrl"/><!--用来提交表单(回显)-->
                            <input type="file" class="form-control" name="file"/><!--用来提交表单(上传)-->
                        </div>
                    </div>

                </form>

            </div>
        <#--模态框底部按钮-->
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary signStoreBtn">保存</button>
            </div>
        </div>
    </div>
</div>


<script>
    $(function () {
     

        //模态框的表单提交 : 保存按钮
        $(".signStoreBtn").click(function () {
            //提交表单
            $("#signStoreForm").submit();
        });
        
        //删除商品 : 删除按钮
        $(".deleteBtn").click(function () {
            var id = $(this).data("tid");
            //发送请求去删除
            $.get('/signStore/delete.do',{id:id});
        });

        
        //添加/修改按钮，弹出模态框
        $(".inputBtn").click(function () {
            //清空模态框的数据
            $("#signStoreModal input").val("");
            $("#photoUrl").attr('src', '');
            //获取当前按钮中的自定义JSON对象
            var obj = $(this).data("json");
            //只有编辑按钮才做数据回显
            if (obj) {
                $("#signStoreModal input[name='id']").val(obj.id);
                $("#signStoreModal input[name='productTitle']").val(obj.productTitle);
                $("#signStoreModal input[name='productPrice']").val(obj.productPrice);
                $("#signStoreModal input[name='productSign']").val(obj.productSign);
                $("#signStoreModal input[name='productUrl']").val(obj.productUrl);
                $("#photoUrl").attr('src', obj.productUrl);
            }
            $("#signStoreModal").modal('show');
        });
    })
    
</script>
<style>
    #inputModal img{
        width:100%
    }

    #inputModal .modal-body{
        max-height: 600px;
        overflow-y: auto;
    }
</style>
</body>
</html>